package com.huawei.hwid.core.b.a.a;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hwid.core.d.b;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.d.p;
import com.huawei.hwid.f.g;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class c extends com.huawei.hwid.core.b.a.a {
    private String h = "/IUserInfoMng/opLog";
    private String i;

    public static class a extends com.huawei.hwid.core.helper.handler.a {
        private Context a;

        public a(Context context) {
            super(context);
            this.a = context;
        }

        public void a(Bundle bundle) {
            super.a(bundle);
            e.e("OpLogRequest", "upload log success", true);
            com.huawei.hwid.core.a.a.a(this.a).a();
            com.huawei.hwid.core.a.c.a(0);
            com.huawei.hwid.core.a.c.a(this.a);
        }

        public void b(Bundle bundle) {
            super.b(bundle);
            com.huawei.hwid.core.a.c.a(0);
            com.huawei.hwid.core.a.c.a(this.a);
        }
    }

    public c(String str) {
        c(1);
        this.i = str;
    }

    public String j() throws IllegalArgumentException, IllegalStateException, IOException {
        return this.i;
    }

    public void a(String str) throws XmlPullParserException, IOException {
        XmlPullParser a = p.a(str.getBytes("UTF-8"));
        for (int eventType = a.getEventType(); 1 != eventType; eventType = a.next()) {
            String name = a.getName();
            switch (eventType) {
                case 2:
                    if (HiAnalyticsConstant.BI_KEY_RESUST.equals(name)) {
                        this.b = g.a(a.getAttributeValue(null, "resultCode"));
                    }
                    if (this.b != 0) {
                        if (!"errorCode".equals(name)) {
                            if (!"errorDesc".equals(name)) {
                                break;
                            }
                            this.d = a.nextText();
                            break;
                        }
                        this.c = g.a(a.nextText());
                        break;
                    }
                    break;
                default:
                    break;
            }
        }
    }

    public String b() {
        return this.h;
    }

    public Bundle c() {
        return super.c();
    }

    public String c(Context context) {
        return b.f(context);
    }

    public void a(Context context, com.huawei.hwid.core.b.a.a aVar, String str, CloudRequestHandler cloudRequestHandler) {
        if (aVar.o() <= 0) {
            str = b.m(context);
            if (TextUtils.isEmpty(str)) {
                aVar.a(context, d(context));
            } else {
                e.a("OpLogRequest", "has alreacdy accountName logined in", true);
            }
        }
        com.huawei.hwid.core.b.a.e.a(context.getApplicationContext(), aVar, str, a(context, aVar, new a(context)));
    }

    public int d(Context context) {
        int i = 0;
        try {
            i = com.huawei.hwid.core.c.a.a(context).a("ip_countrySiteID", 0);
        } catch (Exception e) {
            e.d("OpLogRequest", "siteID in prefrence maybe err", true);
        }
        return i;
    }
}
